using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace TrainTicket.DAO
{
    public class FaqDAO
    {
        private DbConnection _conn;

        public FaqDAO()
        {
            _conn = new DbConnection();
        }

        public DataTable GetAllFaq()
        {
            return _conn.ExecuteDataTable("sp_GetAllFaq", null);
        }

        public DataSet FaqPagingSQL(int currPage, int recodperpage, int Pagesize)
        {
            SqlParameter[] param = new SqlParameter[3];

            param[0] = new SqlParameter("@currPage", SqlDbType.Int);
            param[0].Value = currPage;

            param[1] = new SqlParameter("@recodperpage", SqlDbType.Int);
            param[1].Value = recodperpage;

            param[2] = new SqlParameter("@Pagesize", SqlDbType.Int);
            param[2].Value = Pagesize;

            return _conn.ExecuteDataSet("spFaq_PhanTrang", param);
        }

        public int InsertFaq(string Questions, string Answers)
        {
            SqlParameter []param = new SqlParameter[2];

            param[0] = new SqlParameter("@Quetions", SqlDbType.NText);
            param[0].Value = Questions;

            param[1] = new SqlParameter("@Answers", SqlDbType.NText);
            param[1].Value = Answers;

            return _conn.ExecuteNonQuery("sp_InsertFaq", param);
        }

        public int DeleteFaq(int FaqID)
        {
            SqlParameter param = new SqlParameter();
            param = new SqlParameter("@FaqID", SqlDbType.Int);
            param.Value = FaqID;
            return _conn.ExecuteNonQuery("sp_DeleteFaq", param);
        }

        public int UpdateFaq(int FaqID, string Questions, string Answers)
        {
            SqlParameter[] param = new SqlParameter[3];

            param[0] = new SqlParameter("@FaqId", SqlDbType.Int);
            param[0].Value = FaqID;

            param[1] = new SqlParameter("@Questions", SqlDbType.NText);
            param[1].Value = Questions;

            param[2] = new SqlParameter("@Answers", SqlDbType.NText);
            param[2].Value = Answers;

            return _conn.ExecuteNonQuery("sp_UpdateFaq", param);
        }        
                       
        public DataTable GetFaqById(int FaqID)
        {
            SqlParameter param = new SqlParameter("@FaqId", SqlDbType.Int);
            param.Value = FaqID;

            return _conn.ExecuteDataTable("sp_GetFaqByFaqID", param);
        }

        public int CheckFaqExitsInsert(string Question)
        {
            SqlParameter param = new SqlParameter();

            param = new SqlParameter("@Questions", SqlDbType.NVarChar);
            param.Value = Question;

            return _conn.ExecuteScalar("sp_CheckExitsFaqInsert ", param);
        }

        public int CheckFaqExitsUpdate(int FaqID, string Question)
        {
            SqlParameter[] param = new SqlParameter[2];

            param[0] = new SqlParameter("@FaqID", SqlDbType.Int);
            param[0].Value = FaqID;

            param[1] = new SqlParameter("@Questions", SqlDbType.NVarChar);
            param[1].Value = Question;

            return _conn.ExecuteScalar("sp_CheckExitsFaqUpdate", param);
        }        
    }
}
